package com.zwl9517hotmail.libplaymedia;

import android.content.Context;
import android.util.Log;
import android.view.View;

import cn.jzvd.JZVideoPlayerStandard;

/**
 * Created by ZouWeiLin
 * on 2017/11/24  18:25
 * version:
 * desc:
 */
public class JZVideoPlayerAutoPlay extends JZVideoPlayerStandard {

    private boolean repeat;// 是否需要循环

    public JZVideoPlayerAutoPlay(Context context) {
        super(context);
    }

    @Override
    public void onAutoCompletion() {
        Log.e("tag", "JZVideoPlayerAutoPlay : onAutoCompletion + ");
        int size = urlMap.size();
        int nextIndex = currentUrlMapIndex + 1;
        if (nextIndex < size) {
            // 播放结束时，切换到下一条视频
            onStatePreparingChangingUrl(nextIndex, 0/*跳转到第0秒*/);//参照切换清晰度切换url,调用这个函数可以随时切换url
        } else {
            // 当所有视频播放结束后，判断是否需要重复
            if (repeat) {
                onStatePreparingChangingUrl(0/*从第0个开始播放*/, 0);
            } else {
                // 无法实现重播
//                super.onAutoCompletion();
//                onCompletion();
                // 实现手动点击重播
                currentUrlMapIndex = 0;
                cancelProgressTimer();
                onStateAutoComplete();

            }
        }
    }

    @Override
    public void onCompletion() {
        Log.e("tag", "JZVideoPlayerAutoPlay : onCompletion + ");
    }

    @Override
    public void onClick(View v) {
        retryTextView.setVisibility(GONE);
        super.onClick(v);
    }

    public void setRepeat(boolean repeat) {
        this.repeat = repeat;
    }
}
